package edu.gatech.aristotle.random.util;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Random;


public class RandomnessSelector {
	static public float randomFloat( int seed ){

		float randomValue	= new Random().nextInt(seed) + 1;
		//Debug.println(  randomValue/seed );
		
		return randomValue/seed ;
	}
	/**
	 * select M random charactors from entireSet.
	 * @param entireSet
	 * @param mPercent < 100;
	 * @return
	 */
	static public ArrayList<Integer> selectRandomSubset(ArrayList<Integer> entireSet, int sizeOfRandomSet ){
		int[] randomIndices = selectRandomIndex( entireSet.size(), sizeOfRandomSet );
		
		ArrayList<Integer> randomSubset = new ArrayList<Integer>();
		
		for ( int i = 0; i < sizeOfRandomSet; i++ ){
			int anInt = entireSet.get( randomIndices[i] );
			randomSubset.add( anInt );
		}
		
		return randomSubset;
	}
	
	/** 
	 * Randomly select M integers from 0 to N-1.
	 * @param N
	 * @param M
	 * @return
	 */
	static public int[] selectRandomIndex( int N, int M ){
//		Random random	= new Random();
//		
//		int[] randomIndices = new int[M];
//		for ( int i = 0; i < M; i++ ){
//			randomIndices[i] = random.nextInt( N );
//		}
//				
//		return randomIndices;
		Random random	= new Random();
		
		int[] randomIndices = new int[M];
		HashSet<Integer> randomIndexSet	= new HashSet<Integer>();
		
		while ( randomIndexSet.size() < M){
			randomIndexSet.add( random.nextInt( N ) );
		}
	
		int i = 0;
		
		for ( Integer index : randomIndexSet ){
			randomIndices[i]	= index;
			i++;
		}
		
		return randomIndices;
	}
	

}
